<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <ul class="list-group">
            <li v-for="row in list" class="list-group-item">
                <p>name: {{ row.name }}</p>
                <p>age: {{ row.age }}</p>
                <p>sex: {{ row.sex == 0 ? "男" : "女" }}</p>
            </li>
        </ul>
    </div>
    <script src="./js/bootstrap.min.js"></script>
    <script src="./js/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                list: [],
                mock: false,
            },
            mounted: function() {
                this.getPageList()
            },
            methods: {
                getPageList: function() {
                    if (this.mock) {
                        this.list = [
                            {"name": "张三", "age": 14, "sex": 0},
                            {"name": "王四", "age": 19, "sex": 1},
                        ]
                    }else{
                        fetch("http://localhost:5000/pagelist")
                            .then(res => res.json())
                            .then(res => {
                                if (res.code == 0) {
                                    this.list = res.data
                                } else {
                                    alert(res.msg)
                                }
                            })
                    }
                },
            }
        });
    </script>
</body>
</html>